<?php

#require_once('site_config.php');



function debug_log($name,$msg){
  global $site_global_config;
  
  $log_path = $site_global_config['LOG'];
	  	
	append_to_file($log_path. $name.'.log', $msg."\n");
}

# private
function write_to_file($filename, $filecontent, $filemode=null) {
  error_log("Writing to file:". $filename);
  $fh = fopen($filename, 'w') or die("CommonUtil::WriteFile: can't open file"); // ??? fixme
  //??? fixme no filelock needed?
  fwrite($fh, $filecontent);
  fclose($fh);
  if (! is_null ($filemode)){
    //example: chmod("/somedir/somefile", 0755);  // octal; correct value of mode
    chmod($filename, $filemode); 
  }
}

# private
function append_to_file($filename, $filecontent){
  
  if(file_exists($filename)){
    $fh = fopen($filename, 'a') or die("CommonUtil::AppendFile: can't open file");// ??? fixme
    fwrite($fh, $filecontent);
    fclose($fh);
  } else {    
    WriteFile($filename, $filecontent);
  }
}
?>
